home *** CD-ROM | disk | FTP | other *** search
/ The Games Machine 76 / XENIATGM66.iso / Indiana Jones / Indiana Jones.exe / RESOURCE / PREVIEW.GOB / cog_actor_aisubmachine.cog < prev    next >
Text File  |  1999-11-15  |  7KB  |  320 lines

  1. # ===================================================================
  2. # Jones 3D Cog Script
  3. #
  4. # actor_AISubmachine.cog
  5. #
  6. # [RandyT]
  7. #
  8. # Actor script for any AI with a submachine gun.
  9. #
  10. # (C) 1999 LucasArts Entertainment Company LLC. All Rights Reserved
  11. # ===================================================================
  12.  
  13. symbols
  14.  
  15. message        created
  16. message        damaged
  17. message        killed
  18. message        timer
  19.  
  20. # ************************** TEMPLATES *************************
  21. template    tplGun=submachine            local
  22. template    tplPoisonKit=poisonkit        local
  23. template    tplHealthKit=hlthsml        local
  24. template    tplFire=+bazooka_exp_fire    local
  25. template    tplSmoke=+bazooka_exp_smoke    local
  26. template    tplSparks=lavadeathsparks    local
  27.  
  28. # ************************** WEAPON HANDLERS *******************
  29. int            weaponNum=23                local
  30. int            damageType                    local
  31.  
  32. # ************************** AI VARS ***************************
  33. ai            fists=com_fists.ai            local
  34.  
  35. int            TIMER_ID_WAKEUP_NORMAL=0    local
  36. int            TIMER_ID_WAKEUP_AND_DIE=1    local
  37.  
  38. # ************************** MISC LOCAL VARS *******************
  39. thing        bandito                        local
  40. thing        indy                        local
  41. thing        powerup                        local
  42.  
  43. int            timerID                        local 
  44. int            index                        local
  45. int            numSmallKits                local
  46. int            numBigKits                    local
  47. int            kitTotal                    local
  48. int            bItemCreated                local
  49.  
  50. flex        indyHealth                    local
  51. flex        kitChance                    local
  52.  
  53. vector        dir                            local
  54. vector        randVec                        local
  55.  
  56. # ************************** SUBROUTINES ***********************
  57. flex        Disarm                        local
  58. flex        WhipIt                        local
  59. flex        PushIt                        local
  60. flex        GetKitChance                local
  61. flex        CheckHealthBins                local
  62.  
  63. end
  64.  
  65. # ===================================================================
  66. code
  67.  
  68. # -------------------------------------------------------------------
  69. created:
  70.  
  71.     bandito = GetSenderRef();
  72.     indy = GetLocalPlayerThing();
  73.  
  74.     AISetSubMode(bandito, 0x40000);                            # Set SUBMODE_QUICKMODEFADE
  75.  
  76.     SetWeaponModel(bandito, weaponNum);
  77.     SelectWeapon(bandito, weaponNum);
  78.  
  79.     AIEnableInstinct(bandito, "circlestrafe", 0);
  80.     AIEnableInstinct(bandito, "roam", 0);
  81.  
  82.     return;
  83.  
  84. # -------------------------------------------------------------------
  85. damaged:
  86.  
  87.     bandito = GetSenderRef();
  88.     damageType = GetParam(1);
  89.  
  90.     # Been whipped?
  91.     if (damageType == 0x10)
  92.     {
  93.         call Disarm;
  94.     }
  95.  
  96.     # Been punched?
  97.     else if (damageType == 0x08)
  98.     {
  99.         if ((GetParam(0) < GetThingHealth(bandito)) && (GetParam(0) * 2) > GetThingHealth(bandito))
  100.         {
  101.             # Make sure thing's not already disabled
  102.             if (BitTest(GetActorFlags(bandito), 0x40008)) return;
  103.  
  104.             call Disarm;
  105.  
  106.             # Play dead
  107.             AIKnockOut(bandito, RandBetween(10, 30), TIMER_ID_WAKEUP_NORMAL);
  108.         }
  109.     }
  110.  
  111.     # Jeep or MineCar hit us
  112.     else if (damageType == 0x02000000)
  113.     {
  114.         # If invulnerable or immobile, ignore -- avoids multiple collision problem
  115.         if (BitTest(GetActorFlags(bandito), 0x40008))
  116.         { 
  117.             ReturnEx(0);
  118.             return;
  119.         }
  120.         else if (GetParam(0) >= GetThingHealth(bandito))
  121.         {
  122.             call Disarm;
  123.  
  124.             # Pause long enough to land
  125.             AIRunOver(bandito, RandBetween(5, 6), TIMER_ID_WAKEUP_AND_DIE);
  126.             ReturnEx(0);
  127.             return;
  128.         }
  129.     }
  130.  
  131.     return;
  132.  
  133.  
  134. # -------------------------------------------------------------------
  135. killed:
  136.  
  137.     bandito = GetSenderRef();
  138.     damageType = GetParam(1);
  139.  
  140.     # Killed by lava?
  141.     if (damageType == 0x200)
  142.     {
  143.         Sleep(0.1);
  144.         CreateThing(tplFire, bandito);
  145.         Sleep(0.3);
  146.         CreateThing(tplSmoke, bandito);
  147.         SetThingFlags(bandito, 0x80000);
  148.  
  149.         for (index = 0; index < 10; index = index + 1)
  150.         {
  151.             CreateThing(tplSparks, bandito);
  152.             Sleep(0.03);
  153.         }
  154.     }
  155.     else
  156.     {
  157.         call Disarm;
  158.     }
  159.  
  160.     return;
  161.  
  162. # -------------------------------------------------------------------
  163. timer:
  164.  
  165.     bandito = GetParam(0);
  166.     timerID = GetSenderId();
  167.  
  168.     if (timerID == TIMER_ID_WAKEUP_NORMAL)
  169.     {
  170.         # Knocked out but not killed
  171.         AIKnockOut(bandito, 0, TIMER_ID_WAKEUP_NORMAL);
  172.         SetHealth(bandito, 100.0);
  173.     }
  174.     else if (timerID == TIMER_ID_WAKEUP_AND_DIE)
  175.     {
  176.         # Make sure not invulnerable
  177.         ClearActorFlags(bandito, 0x8);
  178.         # Using scrape damage to avoid infinite loop
  179.         DamageThing(bandito, GetThingMaxHealth(bandito), 0x1000000, GetLocalPlayerThing());
  180.     }
  181.  
  182.     return;
  183.  
  184. # ===================================================================
  185. #    Subroutines
  186. # ===================================================================
  187.  
  188. Disarm: # Note: damageType must already be set!    
  189.  
  190.     if (AIGetArmedMode(bandito) != 0)
  191.     {
  192.         # Swap the gun back out
  193.         ResetWeaponModel(bandito);
  194.  
  195.         # A whipped gun behaves a bit differently...
  196.         if (damageType == 0x10)
  197.         {
  198.             powerup = CreateThing(tplGun, bandito);
  199.             call WhipIt;
  200.             return;
  201.         }
  202.         # We're roadkill...
  203.         else if (damageType == 0x02000000)
  204.         {
  205.             powerup = CreateThing(tplGun, bandito);
  206.             call PushIt;
  207.             return;
  208.         }
  209.  
  210.         # Check our chances of dropping a health kit
  211.         call GetKitChance;
  212.  
  213.         # Create a new weapon, or maybe a health or snake bite kit
  214.         if (Rand() > kitChance)
  215.         {
  216.             powerup = CreateThing(tplGun, bandito);
  217.             call PushIt;
  218.         }
  219.         else
  220.         {
  221.             # Is Indy poisoned?
  222.             if (BitTest(GetActorFlags(indy), 0x2000))
  223.             {
  224.                 # Have any poison kits?
  225.                 if (GetInv(indy, 46) < 1)
  226.                 {
  227.                     if (Rand() < 0.25)
  228.                     {
  229.                         powerup = CreateThing(tplPoisonKit, bandito);
  230.                         call PushIt;
  231.                         return;
  232.                     }
  233.                 }
  234.             }
  235.             
  236.             # If we haven't created anything yet...
  237.             if (!bItemCreated)
  238.             {
  239.                 # See what Indy's already holding
  240.                 call CheckHealthBins;
  241.  
  242.                 if (kitTotal <= 30)
  243.                     powerup = CreateThing(tplHealthKit, bandito);
  244.                 else
  245.                     powerup = CreateThing(tplGun, bandito);
  246.                 
  247.                 call PushIt;
  248.             }
  249.         }
  250.     }
  251.  
  252.     # Reset var for next time...
  253.     bItemCreated = 0;
  254.  
  255.     return;
  256.  
  257. # -------------------------------------------------------------------
  258.  
  259. WhipIt: # Note: powerup must already be initialized!
  260.  
  261.     # Push powerup towards Indy...
  262.     dir = VectorAdd(GetThingPos(GetLocalPlayerThing()), '0.0 0.0 0.75');
  263.     dir = VectorScale(VectorSub(dir, GetThingPos(powerup)), 4.75);
  264.     ApplyForce(powerup, dir);
  265.  
  266.     # Time for fists...
  267.     AISetClass(bandito, fists);
  268.     SelectWeapon(bandito, 19);
  269.  
  270.     return;
  271.  
  272. # -------------------------------------------------------------------
  273.  
  274. PushIt: # Note: powerup must already be initialized!
  275.  
  276.     # Push powerup away a little...
  277.     dir = VectorTransformToOrient(bandito, '-0.17 0.0 0.0');
  278.     randVec = VectorSet(0, Rand() * 360, 0);
  279.     dir = VectorRotate(dir, randVec);
  280.     SetThingVel(powerup, dir);
  281.  
  282.     # Time for fists...
  283.     AISetClass(bandito, fists);
  284.     SelectWeapon(bandito, 19);
  285.     bItemCreated = 1;
  286.  
  287.     return;
  288.  
  289. # -------------------------------------------------------------------
  290.  
  291. GetKitChance:
  292.  
  293.     indyHealth = GetThingHealth(indy);
  294.     if (indyHealth >= 750.0) kitChance = 0.05; 
  295.     else if (indyHealth >= 500.0) kitChance = 0.1;
  296.     else if (indyHealth >= 250.0) kitChance = 0.15;
  297.     else kitChance = 0.25;
  298.  
  299.     return;
  300.  
  301. # -------------------------------------------------------------------
  302.  
  303. CheckHealthBins:
  304.  
  305.     kitTotal = 0;
  306.  
  307.     numSmallKits = GetInv(indy, 39);                # Small herbs
  308.     numSmallKits = numSmallKits + GetInv(indy, 49);    # Small health
  309.  
  310.     numBigKits = GetInv(indy, 38);                    # Big herbs
  311.     numBigKits = numBigKits + GetInv(indy, 48);        # Big health
  312.  
  313.     numSmallKits = numSmallKits * 5;
  314.     numBigKits = numBigKits * 10;
  315.  
  316.     kitTotal = numSmallKits + numBigKits;
  317.  
  318.     return;
  319.  
  320. end